<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      lang="zh-cn">
<head>
    <meta content="云之讯,云通讯,云通讯平台" name="keywords"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1"/>
    <title>短信平台运营系统 - 管理员中心</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <link th:href="@{/resources/css/bootstrap.min14ed.css?v=3.3.6}" rel="stylesheet">
    <link th:href="@{/resources/css/font-awesome.min93e3.css?v=4.4.0}" rel="stylesheet">
    <!-- jqgrid-->
    <link th:href="@{/resources/css/plugins/jqgrid/ui.jqgridffe4.css?0820}" rel="stylesheet">
    <link th:href="@{/resources/css/animate.min.css}" rel="stylesheet">
	<link th:href="@{/resources/css/plugins/sweetalert/sweetalert.css}" rel="stylesheet">

	<link th:href="@{/resources/css/style.min862f.css?v=4.1.0}" rel="stylesheet">
    <style>
        /* Additional style to fix warning dialog position */
        #alertmod_table_list_2 {
            top: 900px !important;
        }
    </style>
</head>
<body class="gray-bg"><div th:replace="stat :: statCode"></div>
	<div class="wrapper wrapper-content animated fadeInRight">
	    <div class="row">
	        <div class="col-sm-12">
	            <div class="ibox ">
	                <div class="ibox-title">
	                    <h5>新建管理员</h5>
	                </div>
	                <div class="ibox-content">

						<div class="pull-right tooltip-demo">
							<a class="btn btn-danger btn-sm" data-toggle="tooltip" data-placement="top" title="返回" onclick="javascript:history.back(-1);"><i class="fa fa-reply"></i>&nbsp;返回</a>
						</div>
	                    <div class="row">
	                        <div class="col-sm-6 b-r">
	                            <form class="form-horizontal m-t" id="manager_form">
	                                <div class="form-group">
	                                    <label class="col-sm-3 control-label">管理员账号</label>
	                                    <div class="col-sm-8">
		                                    <input id="email" type="email" name="email" class="form-control isEmail" aria-required="true" placeholder="邮箱">
	                                    </div>
	                                </div>
	                                <div class="form-group">
	                                	<label class="col-sm-3 control-label">管理员身份</label>
	                                    <div class="col-sm-8">
		                                    <select id="roleList" class="form-control" name="roleId">
								            	<option th:each="role:${roleList}" th:value="${role.id}" th:text="${role.roleName}"></option>
								            </select>
	                                    </div>
	                                </div>
	                                <div class="form-group">
	                                	<label class="col-sm-3 control-label">web应用系统</label>
	                                    <div class="col-sm-8">
								            <select class="form-control" disabled="disabled">
								            	<option value="3">运营平台</option>
								            </select>
								        </div>
								        <input type="hidden" name="webId" value="3"/>
	                                </div>	                                
	                                <div class="form-group">
	                                	<label class="col-sm-3 control-label">真实姓名</label>
	                                	<div class="col-sm-8">
		                                    <input id="realname" name="realname" type="text" class="form-control">
	                                	</div>
	                                </div>
	                                <div class="form-group">
	                                    <label class="col-sm-3 control-label">联系电话</label>
	                                    <div class="col-sm-8">
		                                    <input id="mobile" type="text" name="mobile" class="form-control isMobile" placeholder="手机号码">
	                                    </div>
	                                </div>
	                                <div class="form-group">
	                                    <label class="col-sm-3 control-label">登录密码</label>
	                                    <div class="col-sm-8">
		                                    <input id="password" class="paasword" type="password" class="form-control">
											<label id="pwd-error" class="error" style="display: block;"></label>
	                                    </div>
	                                </div>
								     <div class="form-group">
								        <div class="col-sm-12 col-sm-offset-3">
								            <button class="btn btn-primary btn-sm m-r-md" type="button" id="editButton">添 加</button>
								            <button class="btn btn-white btn-sm" type="reset" id="cancelButton">重 置</button>
								        </div>
								    </div>
	                            </form>
	                        </div>
	                    </div>
	                </div>
	            </div>
	        </div>
	    </div>
	</div>
	<script th:src="@{/resources/js/hex_ha_ha_ha_ha_ha.js}"></script>
	<script th:src="@{/resources/js/jquery.min.js?v=2.1.4}"></script>
	<script th:src="@{/resources/js/bootstrap.min.js?v=3.3.6}"></script>
	<script th:src="@{/resources/js/plugins/peity/jquery.peity.min.js}"></script>
	<script th:src="@{/resources/js/content.min.js?v=1.0.0}"></script>
	<script th:src="@{/resources/js/date_format.min.js?v=1.0.0}"></script>
	<script th:src="@{/resources/js/jquery.form.js?v=1.0.0}"></script>

	<script th:src="@{/resources/js/plugins/sweetalert/sweetalert.min.js}"></script>
	<script th:src="@{/resources/js/plugins/validate/jquery.validate.min.js}"></script>
	<script th:src="@{/resources/js/common.js?v=1.0.0}"></script>
	
	<script th:inline="javascript">
		/*<![CDATA[*/
		var validate;
		$.validator.defaults.ignore = ""; /* 不需要验证的元素*/
		/*表单验证规则*/
		validate = $("#manager_form").validate({
			rules: {
				mobile: {
					required: true
				},
				email: {
					required: true
				},
				realname: {
					required: true,
					minlength: 1,
					maxlength: 60
				}
			},
			messages: {
				mobile: {
					required: "手机号必填"
				},
				email: {
					required: "管理员账号必填"
				},
				realname: {
					required: "请输入名称",
					minlength: "名称不能为空",
					maxlength: "名称字符不能超过60个字符"
				}
			}
		});
		jQuery.validator.addMethod("isEmail", function (value, element) {
			var email =  /^[a-zA-Z]+@ucpaas.com$/;
			return this.optional(element) || (email.test(value));
		}, "必须是云之讯邮箱");
		jQuery.validator.addMethod("isMobile", function (value, element) {
			var mobile =  /^1[34578]\d{9}$/;
			return this.optional(element) || (mobile.test(value));
		}, "请输入正确格式的手机号码");
//		jQuery.validator.addMethod("isPaasword", function (value, element) {
//			var password =  /^\w{6,20}$/;
//			return this.optional(element) || ((password.test(value) && (password.length > 5)) );
//		}, "密码必须是由6-20字母数字下滑线组成的位字符");

		function checkPwd(pwd){
			$("#pwd-error").text("");
			if(pwd.length < 5 || pwd.length > 20){
				$("#pwd-error").text("密码长度限制在6-20位");
                $("#pwd-error").show();
				return false;
			}
			var reg =  /^\w{6,20}$/;
			if(!reg.test(pwd)){
				$("#pwd-error").text("密码只能是6-20位字母、数字或下划线");
                $("#pwd-error").show();

                return false;
			}
			$("#pwd-error").text("");
			return true;
		}

			// 添加或修改管理员
			$("#editButton").on("click",function(){
				if(!validate.form()){return;}
				var password = $("#password").val();
				if(!checkPwd(password)){return ;}
				var options = {
//					beforeSubmit : function() {
//						$(btn).attr("disabled", true);
//					},
					data:{
						password:hex_ha_ha_ha_ha_ha(password)
					},
					success : function(data) {
//						$(btn).attr("disabled", false);

						if(data == null){
							swal("添加失败！", "系统错误，请稍后再试！", "error");
						}else if(data.success == true){
							swal("添加成功！", "信息已保存！", "success");
                            $(".confirm").click(function (){
                                window.location.href = /*[[@{/admin/query}]]*/'';
                            });
						}else{
							swal("添加失败！", data.msg, "error");
						}

					},
					url : /*[[@{/admin/add}]]*/"/add",
					type : "post",
					timeout:30000
				};
				$("#manager_form").ajaxSubmit(options);

			});
		$(function(){
			$("#password").bind("input propertychange",function(){
				checkPwd($("#password").val());
			});


		});


	    /*]]>*/
	    
	</script>
</body>
</html>